//
//  ViewController.m
//  BannerDemo
//
//  Created by 红沙尘 on 2018/12/14.
//  Copyright © 2018年 红沙尘. All rights reserved.
//

#import "ViewController.h"
#import "SGFocusImageFrame.h"
#import "SGFocusImageItem.h"
#import "HSCBannerView.h"

@interface ViewController ()<SGFocusImageFrameDelegate,HSCBannerViewDelegate>

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    NSMutableArray *a = [NSMutableArray array];
    [a addObject:@{@"image":@"http://t2.hddhhn.com/uploads/tu/201812/249/e1827afc90.jpg"}];
    [a addObject:@{@"image":@"http://t2.hddhhn.com/uploads/tu/201812/249/9b86019232.jpg"}];
    [a addObject:@{@"image":@"http://t1.27270.com/uploads/tu/201812/179/6c6b11b723.jpg"}];
    [a addObject:@{@"image":@"http://t1.27270.com/uploads/tu/201812/185/53eb7aa98e.jpg"}];

    CGFloat w = UIScreen.mainScreen.bounds.size.width;
    
    HSCBannerView *bv = [[HSCBannerView alloc] initWithFrame:CGRectMake(0, 200, w, 150)
                                                      offset:30
                                                    dataList:a delegate:self];
    [self.view addSubview:bv];
    
}

#pragma mark - HSCBannerViewDelegate

- (void)bannerView:(HSCBannerView *)view didSelectItem:(HSCBannerItemView *)itemView {
    NSLog(@"%@",itemView.data);
}

- (void)a {
    //添加最后一张图 用于循环
    NSMutableArray *tempArray = [NSMutableArray array];
    [tempArray addObject:@{@"image":@"http://t2.hddhhn.com/uploads/tu/201812/249/e1827afc90.jpg"}];
    [tempArray addObject:@{@"image":@"http://t2.hddhhn.com/uploads/tu/201812/249/9b86019232.jpg"}];
    [tempArray addObject:@{@"image":@"http://t1.27270.com/uploads/tu/201812/179/6c6b11b723.jpg"}];
    [tempArray addObject:@{@"image":@"http://t1.27270.com/uploads/tu/201812/185/53eb7aa98e.jpg"}];
    
    NSMutableArray *itemArray = [NSMutableArray array];
    if (tempArray.count > 1) {
        NSDictionary *dict = [tempArray objectAtIndex:tempArray.count - 1];
        SGFocusImageItem *item = [[SGFocusImageItem alloc] initWithDict:dict tag:-1];
        [itemArray addObject:item];
    }
    
    for (int i = 0; i < tempArray.count; i++) {
        NSDictionary *dict = [tempArray objectAtIndex:i];
        SGFocusImageItem *item = [[SGFocusImageItem alloc] initWithDict:dict tag:i];
        [itemArray addObject:item];
    }
    
    //添加第一张图 用于循环
    if (tempArray.count >1) {
        NSDictionary *dict = [tempArray objectAtIndex:0];
        SGFocusImageItem *item = [[SGFocusImageItem alloc] initWithDict:dict
                                                                    tag:tempArray.count];
        [itemArray addObject:item];
    }
    
    SGFocusImageFrame *bannerView = [[SGFocusImageFrame alloc] initWithFrame:CGRectMake(0, 50, UIScreen.mainScreen.bounds.size.width, 150)
                                                                    delegate:self
                                                                  imageItems:itemArray
                                                                      isAuto:NO];
    [bannerView scrollToIndex:0];
    [self.view addSubview:bannerView];
}

- (void)foucusImageFrame:(SGFocusImageFrame *)imageFrame
           didSelectItem:(SGFocusImageItem *)item {
    NSLog(@"%s \n click===>%@",__FUNCTION__,item.title);
}

- (void)foucusImageFrame:(SGFocusImageFrame *)imageFrame
             currentItem:(int)index {
    NSLog(@"%s \n scrollToIndex===>%d",__FUNCTION__,index);
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
